<?php

namespace app\admin\model\validate;

use app\admin\model\ButtonModel;
use think\Validate;

class Button extends Validate {
    protected $rule =   [
        'name'  => 'max:20',
        //'open_id' => 'require',
        'desc' => 'max:64',
        'key' => 'require|max:24',
        'type' => 'applet_require:小程序APP ID不能为空|require|max:12',
        //'music_id' => 'require',
        'link' => 'max:225',
        'applet_app_id' => 'max:32',
        'applet_path' => 'max:50',
        //'applet_image' => 'max:225',
        'image_url' => 'max:255',
        'group_name' => 'max:20',
    ];

    protected $message  =   [
        'applet_app_id.max' => '小程序APP ID不能超过32个字符 ',
        'applet_path.max' => '小程序路径不能超过50个字符',
        'image_url.max' => '按钮图片地址不能超过225个字符',
        'desc.max' => '描叙不能超过64个字符',
        'name.max'     => '按钮名称不能超过20个字符',
        'key.require'     => '按钮键名不能为空',
        'key.max'     => '按钮键名不能超过24个字符',
        //'music_id' => '相册背景音乐不能为空',
        //'music_name.require' => '相册背景音乐不能为空',
        'type.require' => '按钮类型不能为空',
        'type.max'     => '按钮类型不能超过12个字符',
        'link.max'     => '按钮链接不能超过225个字符',
        //'applet_image' => '小程序跳转封面不能超过225个字符',
        'group_name' => '分组名不能超过20个字符'
    ];

    protected function applet_require($value, $rule, $data) {
        if ($value == ButtonModel::TYPE_APPLET) {
            if (empty($data['applet_app_id'])) {
                return $rule;
            }
        }
        return true;
    }

    protected $scene = [
        /*'add'  =>  ['name','theme','start_time', 'end_time', 'attention_tips', 'cover_image_url', 'sort', 'participate_num'],
        'edit'  =>  ['name','theme','start_time', 'end_time', 'attention_tips', 'cover_image_url', 'sort', 'participate_num'],*/
    ];
}